using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Graphics.Model;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;

using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;
using FlatRedBall.Localization;
using FlatRedBall.Audio;
using Microsoft.Xna.Framework.Media;

using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Input;


#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;
using Rectangle = Microsoft.Xna.Framework.Rectangle;
#endif

using NereusGame.Entities.Ships;

namespace NereusGame.Screens
{
	public partial class Menu
	{
        private const int MAX_BUTTONS = 3;                               // maximum number of buttons
        protected const string CONTENT_MANAGER = "NereusGameContent";   // Name of the contentManager

        private Sprite backGround;                                      // background texture

        //menu buttons
        Sprite startSprite;
        Sprite storySprite;
        Sprite optionsSprite;
        Sprite exitSprite;
        AxisAlignedRectangle startButton;
        AxisAlignedRectangle storyButton;
        AxisAlignedRectangle optionsButton;
        AxisAlignedRectangle exitButton;

		void CustomInitialize()
		{
            ResetCamera(); 
            InitializeBackground();
            InitializeButtons();
            //GlobalContent.InitializeAudio();
		}

        void CustomActivity(bool firstTimeCalled)
        {
            if (InputManager.TouchScreen.ScreenPushed)
            {
                
                if (startButton.IsPointInside(InputManager.TouchScreen.WorldXAt(0.0f), InputManager.TouchScreen.WorldYAt(0.0f)))
                {
                    MoveToScreen(typeof(LoadScreen).FullName);
                }
                else if (optionsButton.IsPointInside(InputManager.TouchScreen.WorldXAt(0.0f), InputManager.TouchScreen.WorldYAt(0.0f)))
                {
                    MoveToScreen(typeof(Options).FullName);
                }
                else if (exitButton.IsPointInside(InputManager.TouchScreen.WorldXAt(0.0f), InputManager.TouchScreen.WorldYAt(0.0f)))
                {
                    GlobalContent.StopAudio();
                    FlatRedBallServices.Game.Exit();                    
                }
                else if (storyButton.IsPointInside(InputManager.TouchScreen.WorldXAt(0.0f), InputManager.TouchScreen.WorldYAt(0.0f)))
                {                    
                    MoveToScreen(typeof(Story).FullName);
                }

            }
        }
        

		void CustomDestroy()
		{
            SpriteManager.RemoveSprite(backGround);

            SpriteManager.RemoveSprite(startSprite);
            SpriteManager.RemoveSprite(optionsSprite);
            SpriteManager.RemoveSprite(storySprite);
            SpriteManager.RemoveSprite(exitSprite);

            ShapeManager.Remove(startButton);
            ShapeManager.Remove(optionsButton);
            ShapeManager.Remove(storyButton);
            ShapeManager.Remove(exitButton);
            
		}

        static void CustomLoadStaticContent(string contentManagerName)
        {


        }

        
        // setup background for this screen
        private void InitializeBackground()
        {
            backGround = new Sprite();
            backGround.Texture = BG;
            SpriteManager.AddSprite(backGround);
            backGround.ScaleX = SpriteManager.Camera.XEdge / 2.35f;  // magic numbers are here to make the image fit the screen LOL
            backGround.ScaleY = SpriteManager.Camera.YEdge / 2.35f;  // magic numbers are here to make the image fit the screen LOL
            backGround.Z = -2;
        }

        // initialzie buttons for this screen
        private void InitializeButtons()
        {
            //start button
            startSprite = SpriteManager.AddSprite(@"Content\Screens\Menu\NewGame.png", "Global");
            startSprite.ScaleY = SpriteManager.Camera.YEdge / 40;
            startSprite.ScaleX = 5f * startSprite.ScaleY;
            startSprite.X = 20.0f;
            startSprite.Y = 0;
            startSprite.Z = -1;

            startSprite.ColorOperation = FlatRedBall.Graphics.ColorOperation.ColorTextureAlpha;
            startSprite.Red = 1;
            startSprite.Green = startSprite.Blue = 0;

            startButton = ShapeManager.AddAxisAlignedRectangle();
            startButton.ScaleY = SpriteManager.Camera.YEdge / 40;
            startButton.ScaleX = 5f * startSprite.ScaleY;
            startButton.X = 20.0f;
            startButton.Y = 0;
            startButton.Visible = false;


            //options button
            optionsSprite = SpriteManager.AddSprite(@"Content\Screens\Menu\Options.png", "Global");
            optionsSprite.ScaleY = SpriteManager.Camera.YEdge / 40;
            optionsSprite.ScaleX = 5f * optionsSprite.ScaleY;
            optionsSprite.X = 20.0f;
            optionsSprite.Y = -5;
            optionsSprite.Z = -1;            

            optionsButton = ShapeManager.AddAxisAlignedRectangle();
            optionsButton.ScaleY = SpriteManager.Camera.YEdge / 40;
            optionsButton.ScaleX = 5f * optionsSprite.ScaleY;
            optionsButton.X = 20.0f;
            optionsButton.Y = -5f;
            optionsButton.Visible = false;

            //story button
            storySprite = SpriteManager.AddSprite(@"Content\Screens\Menu\story.png", "Global");
            storySprite.ScaleY = SpriteManager.Camera.YEdge / 45;
            storySprite.ScaleX = 5f * storySprite.ScaleY;
            storySprite.X = 20.5f;
            storySprite.Y = -10;
            storySprite.Z = -1;

            storyButton = ShapeManager.AddAxisAlignedRectangle();
            storyButton.ScaleY = SpriteManager.Camera.YEdge / 45;
            storyButton.ScaleX = 5f * storyButton.ScaleY;
            storyButton.X = 20.0f;
            storyButton.Y = -10f;
            storyButton.Visible = false;

            //exit button
            exitSprite = SpriteManager.AddSprite(@"Content\Screens\Menu\Exit.png", "Global");
            exitSprite.ScaleY = SpriteManager.Camera.YEdge / 40;
            exitSprite.ScaleX = 5f * exitSprite.ScaleY;
            exitSprite.X = 20.0f;
            exitSprite.Y = -14;
            exitSprite.Z = -1;

            exitButton = ShapeManager.AddAxisAlignedRectangle();
            exitButton.ScaleY = SpriteManager.Camera.YEdge / 40;
            exitButton.ScaleX = 5f * exitSprite.ScaleY;
            exitButton.X = 20.0f;
            exitButton.Y = -14f;
            exitButton.Visible = false;

            

        }


 
        private void ResetCamera()
        {
            // reset camera position
            SpriteManager.Camera.Position = SpriteManager.Camera.Velocity = SpriteManager.Camera.Acceleration = Vector3.Zero; 
            SpriteManager.Camera.Position.Z = 40f;
        }

	}
}
